#if (FEATURE_MODE == 0)
/**
 @file ctc_ipfix_cli.c

 @date 2010-06-09

 @version v2.0

 This file defines functions for ptp cli module

*/

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "sal.h"
 /*#include "ctc_ipfix_cli.h"*/
#include "ctc_ipfix.h"
#include "ctc_api.h"
#include "ctcs_api.h"
#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "drv_api.h"
#include "ctc_xdata_cli.h"


#include "ctc_ipfix_cli.h"

#if 0
#include "ctc_vti_vec.h"
int32
ctc_vti_vec_replace_value(vector v, void* old_val, void* new_val)
{
    uint32 i;

    for (i = 0; i < v->max; i++)
    {
        if (v->index[i] != NULL && v->index[i] == old_val)
        {
            v->index[i] = new_val;
            return 0;
        }
    }

    return -1;
}

/* Install a command into a node. */
void
install_element2(ctc_node_type_t ntype, ctc_cmd_element_t* cmd,ctc_cmd_element_t* old_cmd)
{
    extern vector cmdvec;
    extern vector ctc_cmd_make_descvec(char* string, char** descstr);
    extern  int32 ctc_cmd_cmdsize(vector strvec);
    ctc_cmd_node_t* cnode;

    cnode = vector_slot(cmdvec, ntype);

    if (cnode == NULL)
    {
        ctc_cli_out("Command node %d doesn't exist, please check it\n", ntype);
        return;
    }

    ctc_vti_vec_replace_value(cnode->cmd_vector, old_cmd, cmd);

    cmd->strvec = ctc_cmd_make_descvec(cmd->string, cmd->doc);
    cmd->cmdsize = ctc_cmd_cmdsize(cmd->strvec);


}
#endif
#define MAX_XKEY_FIELD_NUM 8
#define MAX_XDATA_FIELD_NUM 32

#define CTC_CLI_USW_IPFIX_KEY_TYPE_STR "\
| mac-key \
| ipv4-key \
| ipv4-single-key \
| ipv6-key \
| ipv6-single-key \
| mpls-key \
| mpls-single-key \
| l2l3-key \
| udf-key \
| udf-single-key \
"

#define CTC_CLI_USW_IPFIX_KEY_TYPE_DESC \
"Mac key", \
"Ipv4 key", \
"Ipv4 single key", \
"Ipv6 key", \
"Ipv6 single key", \
"Mpls key", \
"Mpls single key", \
"L2l3 key", \
"Udf key", \
"Udf single key"

#define CTC_CLI_USW_IPFIX_KEY_TYPE_SET \
do{\
    index = CTC_CLI_GET_ARGC_INDEX("mac-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_MAC;\
        break;\
    }\
    index = CTC_CLI_GET_ARGC_INDEX("ipv4-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_IPV4;\
        break;\
    }\
    index = CTC_CLI_GET_ARGC_INDEX("ipv4-single-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_IPV4_SINGLE;\
        break;\
    }\
    index = CTC_CLI_GET_ARGC_INDEX("ipv6-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_IPV6;\
        break;\
    }\
    index = CTC_CLI_GET_ARGC_INDEX("ipv6-single-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_IPV6_SINGLE;\
        break;\
    }\
    index = CTC_CLI_GET_ARGC_INDEX("mpls-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_MPLS;\
        break;\
    }\
    index = CTC_CLI_GET_ARGC_INDEX("mpls-single-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_MPLS_SINGLE;\
        break;\
    }\
    index = CTC_CLI_GET_ARGC_INDEX("l2l3-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_L2_L3;\
        break;\
    }\
    index = CTC_CLI_GET_ARGC_INDEX("udf-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_UDF;\
        break;\
    }\
    index = CTC_CLI_GET_ARGC_INDEX("udf-single-key");\
    if (0xFF != index) \
    {\
        flex_key.origin_key_type = CTC_IPFIX_KEY_HASH_UDF_SINGLE;\
        break;\
    }\
}while(0);


/**
 @brief  Initialize sdk IPFIX module CLIs

 @param[in/out]   cli_tree     CLI tree

 @return CTC_E_XXX

*/

extern int32
sys_usw_ipfix_get_entry_by_key(uint8 lchip, ctc_ipfix_data_t* p_key, uint32* p_rst_hit, uint32* p_rst_key_index);
extern int32
sys_usw_ipfix_delete_ad_by_index(uint8 lchip, uint32 index, uint8 dir);
extern int32
sys_usw_ipfix_delete_entry_by_index(uint8 lchip, uint8 type, uint32 index, uint8 dir);
extern int32
sys_usw_ipfix_get_ad_by_index(uint8 lchip, uint32 index, ctc_ipfix_data_t* p_out);
extern int32
sys_usw_ipfix_get_entry_by_index(uint8 lchip, uint32 index, uint8 dir, uint8 key_type, ctc_ipfix_data_t* p_out);
extern int32
sys_usw_ipfix_show_status(uint8 lchip, void *user_data);
extern int32
sys_usw_ipfix_show_stats(uint8 lchip, void *user_data, uint8 is_dump_db, sal_file_t p_f);
extern int32
sys_usw_ipfix_clear_stats(uint8 lchip, void * user_data);
extern int32
sys_usw_ipfix_show_entry_info(ctc_ipfix_data_t* p_info, void* user_data);
extern int32
_ctc_cli_ipfix_parser_mpls_key(ctc_vti_t* vty,unsigned char argc,char** argv, ctc_ipfix_data_t *data);
extern uint32
sys_usw_acl_get_field_id(char * in);
extern void
sys_usw_ipfix_show_kset(uint8 lchip, ctc_ipfix_flex_key_t * ipfix_flex_key);

CTC_CLI(ctc_cli_usw_ipfix_delete_by_index,
        ctc_cli_usw_ipfix_delete_by_index_cmd,
        "ipfix delete (((mac-key|ipv4-key|ipv6-key|mpls-key|l2l3-key|udf-key)(single|))|(flex-key KEY_TYPE)) by index IDX {dir DIR|}",
        CTC_CLI_IPFIX_M_STR,
        "Delete key by cpu",
        "L2 key",
        "Ipv4 key",
        "Ipv6 key",
        "Mpls key",
        "L2l4 key",
        "Udf key",
        "Single key",
        "Flex key",
        "Key type",
        "By",
        "Index",
        "Index value",
        "Direction",
        "<0:Ingress,1:Egress>"
        )
{
    uint32 index = 0;
    uint32 index1 = 0;
    uint8 type = 0;
    int32 ret = CLI_SUCCESS;
    uint8 dir = 0;
    uint8 lchip = 0;

    if (0 == sal_memcmp("mac", argv[0], sal_strlen("mac")))
    {
        type = CTC_IPFIX_KEY_HASH_MAC;
        CTC_CLI_GET_UINT32_RANGE("index", index1, argv[1],0, CTC_MAX_UINT32_VALUE);
    }
    else if (0 == sal_memcmp("ipv4", argv[0], sal_strlen("ipv4")))
    {
        type = CTC_IPFIX_KEY_HASH_IPV4;
        index = CTC_CLI_GET_ARGC_INDEX("single");
        if (index != 0xFF)
        {
            type =  CTC_IPFIX_KEY_HASH_IPV4_SINGLE;
            CTC_CLI_GET_UINT32_RANGE("index", index1, argv[2],0, CTC_MAX_UINT32_VALUE);
        }
        else
        {
            CTC_CLI_GET_UINT32_RANGE("index", index1, argv[1], 0, CTC_MAX_UINT32_VALUE);
        }
    }
    else if (0 == sal_memcmp("ipv6", argv[0], sal_strlen("ipv6")))
    {
        type = CTC_IPFIX_KEY_HASH_IPV6;
        index = CTC_CLI_GET_ARGC_INDEX("single");
        if (index != 0xFF)
        {
            index =  CTC_IPFIX_KEY_HASH_IPV6_SINGLE;
            CTC_CLI_GET_UINT32_RANGE("index", index1, argv[2],0, CTC_MAX_UINT32_VALUE);
        }
        else
        {
            CTC_CLI_GET_UINT32_RANGE("index", index1, argv[1], 0, CTC_MAX_UINT32_VALUE);
        }
    }
    else if (0 == sal_memcmp("mpls", argv[0], sal_strlen("mpls")))
    {
        type = CTC_IPFIX_KEY_HASH_MPLS;
        index = CTC_CLI_GET_ARGC_INDEX("single");
        if (index != 0xFF)
        {
            index =  CTC_IPFIX_KEY_HASH_MPLS_SINGLE;
            CTC_CLI_GET_UINT32_RANGE("index", index1, argv[2], 0, CTC_MAX_UINT32_VALUE);
        }
        else
        {
            CTC_CLI_GET_UINT32_RANGE("index", index1, argv[1], 0, CTC_MAX_UINT32_VALUE);
        }
    }
    else if (0 == sal_memcmp("l2l3", argv[0], sal_strlen("l2l3")))
    {
        type = CTC_IPFIX_KEY_HASH_L2_L3;
        CTC_CLI_GET_UINT32_RANGE("index", index1, argv[1],0, CTC_MAX_UINT32_VALUE);
    }
    else if (0 == sal_memcmp("udf", argv[0], sal_strlen("udf")))
    {
        type = CTC_IPFIX_KEY_HASH_UDF;
        index = CTC_CLI_GET_ARGC_INDEX("single");
        if (index != 0xFF)
        {
            type =  CTC_IPFIX_KEY_HASH_UDF_SINGLE;
            CTC_CLI_GET_UINT32_RANGE("index", index1, argv[2], 0, CTC_MAX_UINT32_VALUE);
        }
        else
        {
            CTC_CLI_GET_UINT32_RANGE("index", index1, argv[1], 0, CTC_MAX_UINT32_VALUE);
        }
    }
    else if(0 == sal_memcmp("flex-key", argv[0], sal_strlen("flex-key")))
    {
        CTC_CLI_GET_UINT32_RANGE("flex-key", type, argv[1], 0, CTC_MAX_UINT32_VALUE);
        CTC_CLI_GET_UINT32_RANGE("index", index1, argv[2], 0, CTC_MAX_UINT32_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("dir");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("dir", dir, argv[index + 1]);
    }
    lchip = g_api_lchip;
    ret = sys_usw_ipfix_delete_ad_by_index(lchip, index1, dir);
    if((DRV_IS_TMM(lchip) || DRV_IS_TMG(lchip)))
    {
        ret = sys_usw_ipfix_delete_ad_by_index(lchip, index1, CTC_EGRESS);
    }
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ret = sys_usw_ipfix_delete_entry_by_index(lchip, type, index1, dir);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_show_status,
        ctc_cli_usw_ipfix_show_status_cmd,
        "show ipfix status ",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Ipfix Status"
        )
{
    int32 ret = CLI_SUCCESS;

    ret = sys_usw_ipfix_show_status(g_api_lchip, NULL);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_show_stats,
        ctc_cli_usw_ipfix_show_stats_cmd,
        "show ipfix stats ",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Ipfix Stats"
        )
{
    int32 ret = CLI_SUCCESS;

    ret = sys_usw_ipfix_show_stats(g_api_lchip, NULL, 0, NULL);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_clear_stats,
        ctc_cli_usw_ipfix_clear_stats_cmd,
        "clear stats ipfix ",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Clear Ipfix Stats"
        )
{
    int32 ret = CLI_SUCCESS;

    ret = sys_usw_ipfix_clear_stats(g_api_lchip, NULL);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_usw_ipfix_show_l2_hashkey,
        ctc_cli_usw_ipfix_show_l2_hashkey_cmd,
        "show ipfix entry-info by entry-key (flex-key KEY_TYPE origin |)mac-key (src-gport SRCPORT|hash-field-sel FIELD_ID){"CTC_CLI_IPFIX_KEY_PORT_STR ""\
        "|profile-id PROFILE_ID |fid FID_VALUE |"CTC_CLI_IPFIX_KEY_CID_STR "|" CTC_CLI_IPFIX_KEY_L2_STR " |" CTC_CLI_IPFIX_XKEY_STR "| xdata array-field FIELD|hash-salt VALUE} "
        "(dir DIR) (detail|)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Entry info",
        "By",
        "Entry key",
        "Flex key",
        "Key type value",
        "Origin",
        "L2 key",
        "Source phyPort",
        CTC_CLI_GPORT_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_VALUE,
        CTC_CLI_KEY_PORT_STR_DESC,
        "Config profile id",
        "Profile id",
        "Fid",
        "Fid Value",
        CTC_CLI_IPFIX_KEY_CID_STR_DESC,
        CTC_CLI_IPFIX_KEY_L2_STR_DESC,
        CTC_CLI_IPFIX_XKEY_STR_DESC,
        "XDATA",
        "(LOCAL) XDATA as KEY-FIELD",
        "[[(LOCAL) XDATA WIDTH ,(LOCAL) XDATA OFFSET ,INVALID ,(LOCAL) XDATA MASK],[...]]",
        "Hash salt",
        "Hash salt Value",
        "Direction",
        "<0:Ingress,1:Egress>",
        "Detail"
        )
{
    ctc_ipfix_data_t use_data;
    uint8 index = 0;
    uint32 rst_hit;
    uint32 rst_key_index;
    int32 ret = CLI_SUCCESS;
    uint32 detail = 0;
    uint32 entry_idx = 0;
    ctc_ipfix_traverse_t ipfix_traverse;
    ctc_field_key_t* p_field = NULL;
    ctc_xdata_field_t xdata_field[35];
    sal_memset(xdata_field, 0, sizeof(ctc_xdata_field_t)*32);
    sal_memset(&ipfix_traverse, 0, sizeof(ctc_ipfix_traverse_t));
    sal_memset(&use_data, 0, sizeof(ctc_ipfix_data_t));

    index = CTC_CLI_GET_ARGC_INDEX("flex-key");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("flex-key", use_data.key_type, argv[index+1], 0, CTC_MAX_UINT32_VALUE);
    }
    else
    {
        use_data.key_type = CTC_IPFIX_KEY_HASH_MAC;
    }

    if(use_data.key_type >= CTC_IPFIX_KEY_HASH_FLEX_BASE)
    {
        use_data.flex_key.field_list = mem_malloc(MEM_CLI_MODULE, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        if (NULL == use_data.flex_key.field_list)
        {
            return CLI_ERROR;
        }
        sal_memset(use_data.flex_key.field_list, 0, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        p_field = use_data.flex_key.field_list;
        CTC_CLI_IPFIX_XKEY_FIELD_HASH_SET(p_field, CTC_CLI_IPFIX_KEY_ARG_CHECK(use_data.flex_key.field_num, MAX_XKEY_FIELD_NUM, p_field));
    }
    
    index = CTC_CLI_GET_ARGC_INDEX("xdata");
    if (0xFF != index)
    {
        use_data.xdata.num = ctc_cmd_get_map_array(1,(void*) (xdata_field),argv[index+2]);
        use_data.xdata.fields = xdata_field;
    }

    index = CTC_CLI_GET_ARGC_INDEX("src-gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("src-gport", use_data.gport, argv[index+1], 0, CTC_MAX_UINT32_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }
    index = CTC_CLI_GET_ARGC_INDEX("hash-field-sel");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("hash-field-sel", use_data.field_sel_id, argv[index+1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("profile-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("profile-id", use_data.profile_id, argv[index + 1],0,CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("fid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("fid", use_data.fid, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("gport", use_data.gport, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("logic-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("lport", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_LOGIC_PORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("metadata");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("metadata", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_METADATA;
    }

    index = CTC_CLI_GET_ARGC_INDEX("mac-da");
    if (index != 0xFF)
    {
        CTC_CLI_GET_MAC_ADDRESS("mac-da", use_data.dst_mac, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("mac-sa");
    if (index != 0xFF)
    {
        CTC_CLI_GET_MAC_ADDRESS("mac-sa", use_data.src_mac, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("eth-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("ether type", use_data.ether_type, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("svlan");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("svlan", use_data.svlan, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_SVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cvlan");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("cvlan", use_data.cvlan, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_CVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("svlan-prio");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("svlan prio", use_data.svlan_prio, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_SVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cvlan-prio");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("cvlan prio", use_data.cvlan_prio, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_CVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("svlan-cfi");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("svlan cfi", use_data.svlan_cfi, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_SVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cvlan-cfi");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("cvlan cfi", use_data.cvlan_cfi, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_CVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("src-cid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("src cid", use_data.src_cid, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_SRC_CID_VALID;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dst-cid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("dst cid", use_data.dst_cid, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_DST_CID_VALID;
    }

    index = CTC_CLI_GET_ARGC_INDEX("hash-salt");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("hash salt", use_data.hash_salt, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_RESOLVE_HASH_CONFLICT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dir");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("dir", use_data.dir, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("detail");
    if (index != 0xFF)
    {
        detail = 1;
    }
    
    ret = sys_usw_ipfix_get_entry_by_key(g_api_lchip, &use_data, &rst_hit, &rst_key_index);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

    ret = sys_usw_ipfix_get_ad_by_index(g_api_lchip, rst_key_index, &use_data);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

    ctc_cli_out("\n%-11s%-18s%-7s%-8s%-9s%-9s%-12s%-10s%-5s\n", "ENTRY_IDX", "ENTRY_TYPE", "PORT", "SEL_ID", "MAX_TTL", "MIN_TTL", "TIMESTAMP", "DIR", "PP");
    ctc_cli_out("----------------------------------------------------------------------------------------\n");

    if (detail == 1)
    {
        entry_idx = rst_key_index + (detail<<31);
    }
    else
    {
        entry_idx = rst_key_index;
    }
    ipfix_traverse.lchip_id = g_api_lchip;
    use_data.key_index = entry_idx;
    ret = sys_usw_ipfix_show_entry_info(&use_data, &ipfix_traverse);
    mem_free(use_data.flex_key.field_list);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_show_l2l3_hashkey,
        ctc_cli_usw_ipfix_show_l2l3_hashkey_cmd,
        "show ipfix entry-info by entry-key (flex-key KEY_TYPE origin |)l2l3-key (src-gport SRCPORT| hash-field-sel FIELD_ID)" CTC_CLI_IPFIX_L2_L3_KEY_STR "|" CTC_CLI_IPFIX_KEY_CID_STR "|" CTC_CLI_IPFIX_XKEY_STR "| xdata array-field FIELD |hash-salt VALUE} (dir DIR) (detail|)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Entry info",
        "By",
        "Entry key",
        "Flex key",
        "Key type value",
        "Origin",
        "L2L3 key",
        "Source phyPort",
        CTC_CLI_GPORT_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_VALUE,
        CTC_CLI_IPFIX_L2_L3_KEY_STR_DESC,
        CTC_CLI_IPFIX_KEY_CID_STR_DESC,
        CTC_CLI_IPFIX_XKEY_STR_DESC,
        "XDATA",
        "(LOCAL) XDATA as KEY-FIELD",
        "[[(LOCAL) XDATA WIDTH ,(LOCAL) XDATA OFFSET ,INVALID ,(LOCAL) XDATA MASK],[...]]",
        "Hash salt",
        "Hash salt Value",
        "Direction",
        "<0:Ingress,1:Egress>",
        "Detail")
{
    ctc_ipfix_data_t use_data;
    uint8 index = 0;
    uint8 mask_len = 0;
    uint32 temp = 0;
    uint32 rst_hit = 0;
    uint32 rst_key_index = 0;
    int32 ret = CLI_SUCCESS;
    uint32 detail = 0;
    uint32 entry_idx = 0;
    ctc_ipfix_traverse_t ipfix_traverse;
    ctc_field_key_t* p_field = NULL;
    ctc_xdata_field_t xdata_field[35];
    sal_memset(xdata_field, 0, sizeof(ctc_xdata_field_t)*35);
    sal_memset(&ipfix_traverse, 0, sizeof(ctc_ipfix_traverse_t));
    sal_memset(&use_data, 0, sizeof(ctc_ipfix_data_t));

    index = CTC_CLI_GET_ARGC_INDEX("flex-key");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("flex-key", use_data.key_type, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }
    else
    {
        use_data.key_type = CTC_IPFIX_KEY_HASH_L2_L3;
    }

    if (use_data.key_type >= CTC_IPFIX_KEY_HASH_FLEX_BASE)
    {
        use_data.flex_key.field_list = mem_malloc(MEM_CLI_MODULE, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        if (NULL == use_data.flex_key.field_list)
        {
            return CLI_ERROR;
        }
        sal_memset(use_data.flex_key.field_list, 0, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        p_field = use_data.flex_key.field_list;
        CTC_CLI_IPFIX_XKEY_FIELD_HASH_SET(p_field, CTC_CLI_IPFIX_KEY_ARG_CHECK(use_data.flex_key.field_num, MAX_XKEY_FIELD_NUM, p_field));
    }
    index = CTC_CLI_GET_ARGC_INDEX("xdata");
    if (0xFF != index)
    {
        use_data.xdata.num = ctc_cmd_get_map_array(1,(void*) (xdata_field),argv[index+2]);
        use_data.xdata.fields = xdata_field;
    }
    index = CTC_CLI_GET_ARGC_INDEX("src-gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("src-gport", use_data.gport, argv[index+1], 0, CTC_MAX_UINT32_VALUE);        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }
    index = CTC_CLI_GET_ARGC_INDEX("hash-field-sel");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("hash-field-sel", use_data.field_sel_id, argv[index+1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("profile-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("profile-id", use_data.profile_id, argv[index + 1],0,CTC_MAX_UINT8_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("gport", use_data.gport, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("logic-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("lport", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_LOGIC_PORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("metadata");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("metadata", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_METADATA;
    }

    index = CTC_CLI_GET_ARGC_INDEX("mac-da");
    if (index != 0xFF)
    {
        CTC_CLI_GET_MAC_ADDRESS("mac-da", use_data.dst_mac, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("mac-sa");
    if (index != 0xFF)
    {
        CTC_CLI_GET_MAC_ADDRESS("mac-sa", use_data.src_mac, argv[index + 1]);
    }


    index = CTC_CLI_GET_ARGC_INDEX("wlan-radio-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("radio-id", use_data.l4_info.wlan.radio_id, argv[index+1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("wlan-radio-mac");
    if (index != 0xFF)
    {
        CTC_CLI_GET_MAC_ADDRESS("radio-mac", use_data.l4_info.wlan.radio_mac, argv[index+1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("wlan-is-ctl-pkt");
    if (index != 0xFF)
    {
        use_data.l4_info.wlan.is_ctl_pkt = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("eth-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("ether type", use_data.ether_type, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("svlan");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("svlan", use_data.svlan, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_SVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("svlan-prio");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("svlan piro", use_data.svlan_prio, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_SVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("svlan-cfi");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("svlan cfi", use_data.svlan_cfi, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_SVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cvlan");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("cvlan", use_data.cvlan, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_CVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cvlan-prio");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("cvlan prio", use_data.cvlan_prio, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_CVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cvlan-cfi");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("cvlan cfi", use_data.cvlan_cfi, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.flags |= CTC_IPFIX_DATA_CVLAN_TAGGED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-sa");
    if (index != 0xFF)
    {
        CTC_CLI_GET_IPV4_ADDRESS("ipsa", temp, argv[index+1]);
        CTC_CLI_GET_UINT8_RANGE("mask", mask_len, argv[index+3],0, CTC_MAX_UINT8_VALUE);
        use_data.l3_info.ipv4.ipsa = temp;
        use_data.l3_info.ipv4.ipsa_masklen = mask_len;
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-da");
    if (index != 0xFF)
    {
        CTC_CLI_GET_IPV4_ADDRESS("ipda", temp, argv[index+1]);
        CTC_CLI_GET_UINT8_RANGE("mask", mask_len, argv[index+3],0, CTC_MAX_UINT8_VALUE);
        use_data.l3_info.ipv4.ipda = temp;
        use_data.l3_info.ipv4.ipda_masklen = mask_len;
    }
    index = CTC_CLI_GET_ARGC_INDEX("src-cid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("src cid", use_data.src_cid, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_SRC_CID_VALID;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dst-cid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("dst cid", use_data.dst_cid, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_DST_CID_VALID;
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-src-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("l4-src", use_data.l4_info.l4_port.source_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-dst-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("l4-dst", use_data.l4_info.l4_port.dest_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("icmp-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("icmp-type", use_data.l4_info.icmp.icmp_type, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("icmp-code");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("icmp-code", use_data.l4_info.icmp.icmpcode, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("igmp-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("igmp-type", use_data.l4_info.igmp.igmp_type, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("tcp-flags");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("tcp-flags", use_data.l4_info.tcp_flags, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("gre-key");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("gre-key", use_data.l4_info.gre_key, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("vni");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("vni", use_data.l4_info.vni, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ttl");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("ttl", use_data.l3_info.ipv4.ttl, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("vrfid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("vrfid", use_data.l3_info.vrfid, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("fid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("fid", use_data.fid, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("dscp", use_data.l3_info.ipv4.dscp, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ecn");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("ecn", use_data.l3_info.ipv4.ecn, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-sub-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("l4-sub-type", use_data.l4_info.l4_sub_type, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-protocol");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("ip-protocol", use_data.l4_info.type.ip_protocol, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-identification");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("ip-identification", use_data.l3_info.ipv4.ip_identification, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-frag");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("ip-frag", use_data.l3_info.ip_frag, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("aware-tunnel-info-en");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("aware-tunnel-info-en", use_data.l4_info.aware_tunnel_info_en, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("l4-type", use_data.l4_info.type.l4_type, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("arp-sender-ip");
    if (index != 0xFF)
    {
        CTC_CLI_GET_IPV4_ADDRESS("arp-sender-ip", temp, argv[index + 1]);
        use_data.l3_info.arp.sender_ip = temp;
    }

    index = CTC_CLI_GET_ARGC_INDEX("arp-target-ip");
    if (index != 0xFF)
    {
        CTC_CLI_GET_IPV4_ADDRESS("arp-target-ip", temp, argv[index + 1]);
        use_data.l3_info.arp.target_ip = temp;
    }

    index = CTC_CLI_GET_ARGC_INDEX("arp-sender-mac");
    if (index != 0xFF)
    {
        CTC_CLI_GET_MAC_ADDRESS("arp-sender-mac", use_data.l3_info.arp.sender_mac, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("arp-target-mac");
    if (index != 0xFF)
    {
        CTC_CLI_GET_MAC_ADDRESS("arp-target-mac", use_data.l3_info.arp.target_mac, argv[index + 1]);
    }
    
    index = CTC_CLI_GET_ARGC_INDEX("arp-op-code");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("arp-op-code", use_data.l3_info.arp.op_code, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("hash-salt");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("hash salt", use_data.hash_salt, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_RESOLVE_HASH_CONFLICT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dir");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("dir", use_data.dir, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("detail");
    if (index != 0xFF)
    {
        detail = 1;
    }
    
    _ctc_cli_ipfix_parser_mpls_key(vty, argc, &argv[0], &use_data);

    ret = sys_usw_ipfix_get_entry_by_key(g_api_lchip, &use_data, &rst_hit, &rst_key_index);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

    ret = sys_usw_ipfix_get_ad_by_index(g_api_lchip, rst_key_index, &use_data);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

     ctc_cli_out("\n%-11s%-18s%-7s%-8s%-9s%-9s%-12s%-10s%-5s\n", "ENTRY_IDX", "ENTRY_TYPE", "PORT", "SEL_ID", "MAX_TTL", "MIN_TTL", "TIMESTAMP", "DIR", "PP");
    ctc_cli_out("---------------------------------------------------------------------------\n");
    if (detail == 1)
    {
        entry_idx = rst_key_index + (detail<<31);
    }
    else
    {
        entry_idx = rst_key_index;
    }
    ipfix_traverse.lchip_id = g_api_lchip;
    use_data.key_index = entry_idx;
    ret = sys_usw_ipfix_show_entry_info(&use_data, &ipfix_traverse);
    mem_free(use_data.flex_key.field_list);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_show_ipv4_hashkey,
        ctc_cli_usw_ipfix_show_ipv4_hashkey_cmd,
        "show ipfix entry-info by entry-key (flex-key KEY_TYPE origin |)ipv4-key (single|)(src-gport SRCPORT|hash-field-sel FIELD_ID){profile-id PROFILE_ID |"CTC_CLI_IPFIX_KEY_PORT_STR "|" CTC_CLI_IPFIX_KEY_CID_STR "|vrfid VRFID_VALUE| fid FID_VALUE |"CTC_CLI_IPFIX_KEY_L3_STR"|"CTC_CLI_IPFIX_KEY_IPV4_L4_STR"|" CTC_CLI_IPFIX_XKEY_STR "| xdata array-field FIELD |hash-salt VALUE} (dir DIR) (detail|)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Entry info",
        "By",
        "Entry key",
        "Flex key",
        "Key type value",
        "Origin",
        "Ipv4 key",
        "Single ipv4 key",
        "Source phyPort",
        CTC_CLI_GPORT_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_VALUE,
        "Config profile id",
        "Profile id",
        CTC_CLI_KEY_PORT_STR_DESC,
        CTC_CLI_IPFIX_KEY_CID_STR_DESC,
        "Vrfid",
        "VRFID_VALUE",
        "Fid",
        "FID_VALUE",
        CTC_CLI_IPFIX_KEY_L3_STR_DESC,
        CTC_CLI_IPFIX_KEY_IPV4_L4_STR_DESC,
        CTC_CLI_IPFIX_XKEY_STR_DESC,
        "XDATA",
        "(LOCAL) XDATA as KEY-FIELD",
        "[[(LOCAL) XDATA WIDTH ,(LOCAL) XDATA OFFSET ,INVALID ,(LOCAL) XDATA MASK],[...]]",
        "Hash salt",
        "Hash salt Value",
        "Direction",
        "<0:Ingress,1:Egress>",
        "Detail")
{
    ctc_ipfix_data_t use_data;
    uint8 index = 0;
    uint8 mask_len = 0;
    uint32 temp = 0;
    uint32 rst_hit = 0;
    uint32 rst_key_index = 0;
    int32 ret = CLI_SUCCESS;
    uint32 detail = 0;
    uint32 entry_idx = 0;
    ctc_ipfix_traverse_t ipfix_traverse;
    ctc_field_key_t* p_field = NULL;
    ctc_xdata_field_t xdata_field[35];
    sal_memset(xdata_field, 0, sizeof(ctc_xdata_field_t)*35);
    sal_memset(&ipfix_traverse, 0, sizeof(ctc_ipfix_traverse_t));
    sal_memset(&use_data, 0, sizeof(ctc_ipfix_data_t));

    index = CTC_CLI_GET_ARGC_INDEX("flex-key");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("flex-key", use_data.key_type, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }
    else
    {
        index = CTC_CLI_GET_ARGC_INDEX("single");
        if (index != 0xFF)
        {
            use_data.key_type = CTC_IPFIX_KEY_HASH_IPV4_SINGLE;
        }
        else
        {
            use_data.key_type = CTC_IPFIX_KEY_HASH_IPV4;
        }
    }

    if (use_data.key_type >= CTC_IPFIX_KEY_HASH_FLEX_BASE)
    {
        use_data.flex_key.field_list = mem_malloc(MEM_CLI_MODULE, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        if (NULL == use_data.flex_key.field_list)
        {
            return CLI_ERROR;
        }
        sal_memset(use_data.flex_key.field_list, 0, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        p_field = use_data.flex_key.field_list;
        CTC_CLI_IPFIX_XKEY_FIELD_HASH_SET(p_field, CTC_CLI_IPFIX_KEY_ARG_CHECK(use_data.flex_key.field_num, MAX_XKEY_FIELD_NUM, p_field));
    }

    index = CTC_CLI_GET_ARGC_INDEX("xdata");
    if (0xFF != index)
    {
        use_data.xdata.num = ctc_cmd_get_map_array(1,(void*) (xdata_field),argv[index+2]);
        use_data.xdata.fields = xdata_field;
    }

    index = CTC_CLI_GET_ARGC_INDEX("src-gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("src-gport", use_data.gport, argv[index+1], 0, CTC_MAX_UINT32_VALUE);        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }
    index = CTC_CLI_GET_ARGC_INDEX("hash-field-sel");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("hash-field-sel", use_data.field_sel_id, argv[index+1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("profile-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("profile-id", use_data.profile_id, argv[index + 1],0,CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("gport", use_data.gport, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("logic-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("lport", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_LOGIC_PORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("metadata");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("metadata", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_METADATA;
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-sa");
    if (index != 0xFF)
    {
        CTC_CLI_GET_IPV4_ADDRESS("ipsa", temp, argv[index+1]);
        CTC_CLI_GET_UINT8_RANGE("mask", mask_len, argv[index+3],0, CTC_MAX_UINT8_VALUE);
        use_data.l3_info.ipv4.ipsa = temp;
        use_data.l3_info.ipv4.ipsa_masklen = mask_len;

    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-da");
    if (index != 0xFF)
    {
        CTC_CLI_GET_IPV4_ADDRESS("ipda", temp, argv[index+1]);
        CTC_CLI_GET_UINT8_RANGE("mask", mask_len, argv[index+3],0, CTC_MAX_UINT8_VALUE);
        use_data.l3_info.ipv4.ipda = temp;
        use_data.l3_info.ipv4.ipda_masklen = mask_len;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("dscp", use_data.l3_info.ipv4.dscp, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("ttl");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("ttl", use_data.l3_info.ipv4.ttl, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("src-cid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("src cid", use_data.src_cid, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_SRC_CID_VALID;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dst-cid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("dst cid", use_data.dst_cid, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_DST_CID_VALID;
    }

    index = CTC_CLI_GET_ARGC_INDEX("vrfid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("vrfid", use_data.l3_info.vrfid, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("fid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("fid", use_data.fid, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ecn");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("ecn", use_data.l3_info.ipv4.ecn, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("ip-protocol");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("ip-protocol", use_data.l4_info.type.ip_protocol, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }
    
    index = CTC_CLI_GET_ARGC_INDEX("l4-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("l4-type", use_data.l4_info.type.l4_type, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-sub-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("l4-sub-type", use_data.l4_info.l4_sub_type, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("aware-tunnel-info-en");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("aware-tunnel-info-en", use_data.l4_info.aware_tunnel_info_en, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-src-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("l4-src", use_data.l4_info.l4_port.source_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-dst-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("l4-dst", use_data.l4_info.l4_port.dest_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("icmp-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("icmp-type", use_data.l4_info.icmp.icmp_type, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("icmp-code");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("icmp-code", use_data.l4_info.icmp.icmpcode, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("igmp-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("igmp-type", use_data.l4_info.igmp.igmp_type, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("tcp-flags");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("tcp-flags", use_data.l4_info.tcp_flags, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-frag");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("ip-frag", use_data.l3_info.ip_frag, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("ip-identification");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("ip-identification", use_data.l3_info.ipv4.ip_identification, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("ip-pkt-len");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("ip-pkt-len", use_data.l3_info.ipv4.ip_pkt_len, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("gre-key");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("gre-key", use_data.l4_info.gre_key, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("vni");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("vni", use_data.l4_info.vni, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("hash-salt");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("hash salt", use_data.hash_salt, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_RESOLVE_HASH_CONFLICT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dir");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("dir", use_data.dir, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("detail");
    if (index != 0xFF)
    {
        detail = 1;
    }

    ret = sys_usw_ipfix_get_entry_by_key(g_api_lchip, &use_data, &rst_hit, &rst_key_index);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

    ret = sys_usw_ipfix_get_ad_by_index(g_api_lchip, rst_key_index, &use_data);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

    ctc_cli_out("\n%-11s%-18s%-7s%-8s%-9s%-9s%-12s%-10s%-5s\n", "ENTRY_IDX", "ENTRY_TYPE", "PORT", "SEL_ID", "MAX_TTL", "MIN_TTL", "TIMESTAMP", "DIR", "PP");
    ctc_cli_out("----------------------------------------------------------------------------------------------\n");
    if (detail == 1)
    {
        entry_idx = rst_key_index + (detail<<31);
    }
    else
    {
        entry_idx = rst_key_index;
    }
    ipfix_traverse.lchip_id = g_api_lchip;
    use_data.key_index = entry_idx;
    ret = sys_usw_ipfix_show_entry_info(&use_data, &ipfix_traverse);
    mem_free(use_data.flex_key.field_list);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_show_mpls_hashkey,
        ctc_cli_usw_ipfix_show_mpls_hashkey_cmd,
        "show ipfix entry-info by entry-key (flex-key KEY_TYPE origin |)mpls-key (single|)(src-gport SRCPORT| hash-field-sel FIELD_ID){profile-id PROFILE_ID| fid FID_VALUE |"CTC_CLI_IPFIX_KEY_PORT_STR "|" CTC_CLI_IPFIX_KEY_MPLS_STR "|" CTC_CLI_IPFIX_XKEY_STR "| xdata array-field FIELD|hash-salt VALUE}" " (dir DIR) (detail|) ",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Entry info",
        "By",
        "Entry key",
        "Flex key",
        "Key type value",
        "Origin",
        "Mpls key",
        "Single mpls key",
        "Source phyPort",
        CTC_CLI_GPORT_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_VALUE,
        "Config profile id",
        "Profile id",
        "FID",
        "FID Value",
        CTC_CLI_KEY_PORT_STR_DESC,
        CTC_CLI_IPFIX_KEY_MPLS_STR_DESC,
        CTC_CLI_IPFIX_XKEY_STR_DESC,
        "XDATA",
        "(LOCAL) XDATA as KEY-FIELD",
        "[[(LOCAL) XDATA WIDTH ,(LOCAL) XDATA OFFSET ,INVALID ,(LOCAL) XDATA MASK],[...]]",
        "Hash salt",
        "Hash salt Value",
        "Direction",
        "<0:Ingress,1:Egress>",
        "Detail")
{
    ctc_ipfix_data_t use_data;
    uint8 index = 0;
    uint32 rst_hit = 0;
    uint32 rst_key_index = 0;
    int32 ret = CLI_SUCCESS;
    uint32 detail = 0;
    uint32 entry_idx = 0;
    ctc_ipfix_traverse_t ipfix_traverse;
    ctc_field_key_t* p_field = NULL;
    ctc_xdata_field_t xdata_field[35];
    sal_memset(xdata_field, 0, sizeof(ctc_xdata_field_t)*35);
    sal_memset(&ipfix_traverse, 0, sizeof(ctc_ipfix_traverse_t));
    sal_memset(&use_data, 0, sizeof(ctc_ipfix_data_t));

    index = CTC_CLI_GET_ARGC_INDEX("flex-key");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("flex-key", use_data.key_type, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }
    else
    {
        index = CTC_CLI_GET_ARGC_INDEX("single");
        if (index != 0xFF)
        {
            use_data.key_type = CTC_IPFIX_KEY_HASH_MPLS_SINGLE;
        }
        else
        {
            use_data.key_type = CTC_IPFIX_KEY_HASH_MPLS;
        }
    }

    if (use_data.key_type >= CTC_IPFIX_KEY_HASH_FLEX_BASE)
    {
        use_data.flex_key.field_list = mem_malloc(MEM_CLI_MODULE, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        if (NULL == use_data.flex_key.field_list)
        {
            return CLI_ERROR;
        }
        sal_memset(use_data.flex_key.field_list, 0, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        p_field = use_data.flex_key.field_list;
        CTC_CLI_IPFIX_XKEY_FIELD_HASH_SET(p_field, CTC_CLI_IPFIX_KEY_ARG_CHECK(use_data.flex_key.field_num, MAX_XKEY_FIELD_NUM, p_field));
    }

    index = CTC_CLI_GET_ARGC_INDEX("xdata");
    if (0xFF != index)
    {
        use_data.xdata.num = ctc_cmd_get_map_array(1,(void*) (xdata_field),argv[index+2]);
        use_data.xdata.fields = xdata_field;
    }

    index = CTC_CLI_GET_ARGC_INDEX("src-gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("src-gport", use_data.gport, argv[index+1], 0, CTC_MAX_UINT32_VALUE);        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }
    index = CTC_CLI_GET_ARGC_INDEX("hash-field-sel");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("hash-field-sel", use_data.field_sel_id, argv[index+1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("profile-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("profile-id", use_data.profile_id, argv[index + 1],0,CTC_MAX_UINT8_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("fid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("fid", use_data.fid, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("gport", use_data.gport, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("logic-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("lport", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_LOGIC_PORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("metadata");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("metadata", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_METADATA;
    }

    _ctc_cli_ipfix_parser_mpls_key(vty, argc, &argv[0], &use_data);

    index = CTC_CLI_GET_ARGC_INDEX("hash-salt");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("hash salt", use_data.hash_salt, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_RESOLVE_HASH_CONFLICT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dir");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("dir", use_data.dir, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("detail");
    if (index != 0xFF)
    {
        detail = 1;
    }

    ret = sys_usw_ipfix_get_entry_by_key(g_api_lchip, &use_data, &rst_hit, &rst_key_index);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

    ret = sys_usw_ipfix_get_ad_by_index(g_api_lchip, rst_key_index, &use_data);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

     ctc_cli_out("\n%-11s%-18s%-7s%-8s%-9s%-9s%-12s%-10s%-5s\n", "ENTRY_IDX", "ENTRY_TYPE", "PORT", "SEL_ID", "MAX_TTL", "MIN_TTL", "TIMESTAMP", "DIR", "PP");
    ctc_cli_out("---------------------------------------------------------------------------------------------\n");
    if (detail == 1)
    {
        entry_idx = rst_key_index + (detail<<31);
    }
    else
    {
        entry_idx = rst_key_index;
    }
    ipfix_traverse.lchip_id = g_api_lchip;
    use_data.key_index = entry_idx;
    ret = sys_usw_ipfix_show_entry_info(&use_data, &ipfix_traverse);
    mem_free(use_data.flex_key.field_list);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_show_ipv6_hashkey,
        ctc_cli_usw_ipfix_show_ipv6_hashkey_cmd,
        "show ipfix entry-info by entry-key (flex-key KEY_TYPE origin |)ipv6-key (single|)(src-gport SRCPORT |hash-field-sel FIELD_ID){profile-id PROFILE_ID|fid FID_VALUE|"CTC_CLI_IPFIX_KEY_PORT_STR "| ip-sa X:X::X:X mask-len LEN| ip-da X:X::X:X mask-len LEN|dscp DSCP|flow-label FLOW_LABEL|ttl TTL|ecn ECN|tcp-flags VALUE|ip-frag FRAG|ip-protocol PROTOCOL|wlan-radio-id ID|wlan-radio-mac MAC|wlan-is-ctl-pkt|"CTC_CLI_IPFIX_KEY_CID_STR "|"CTC_CLI_IPFIX_KEY_L4_STR"|" CTC_CLI_IPFIX_XKEY_STR "| xdata array-field FIELD |hash-salt VALUE} (dir DIR) (detail|) ",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Entry info",
        "By",
        "Entry key",
        "Flex key",
        "Key type value",
        "Origin",
        "Ipv6 key",
        "Single ipv6 key",
        "Source phyPort",
        CTC_CLI_GPORT_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_VALUE,
        "Config profile id",
        "Profile id",
        "Fid",
        "FID Value",
        CTC_CLI_KEY_PORT_STR_DESC,
        "IP-sa",
        CTC_CLI_IPV6_FORMAT,
        "Mask-len",
        "Mask len value<8,12,16,...,128>",
        "IP-da",
        CTC_CLI_IPV6_FORMAT,
        "Mask-len",
        "Mask len value<8,12,16,...,128>",
        "DSCP",
        "DSCP value",
        "Flow label",
        "Flow label value, it will cover l4_port",
        "TTL",
        "TTL Value",
        "Ecn",
        "Ecn value",
        "TCP-flags",
        "Flags value",
        "IP-frag",
        "IP fragement value",
        "IP-protocol",
        "IP protocol value",
        "Radio-id",
        "ID value",
        "Radio mac",
        CTC_CLI_MAC_FORMAT,
        "Is wlan control packet",
        CTC_CLI_IPFIX_KEY_CID_STR_DESC,
        CTC_CLI_IPFIX_KEY_L4_STR_DESC,
        CTC_CLI_IPFIX_XKEY_STR_DESC,
        "XDATA",
        "(LOCAL) XDATA as KEY-FIELD",
        "[[(LOCAL) XDATA WIDTH ,(LOCAL) XDATA OFFSET ,INVALID ,(LOCAL) XDATA MASK],[...]]",
        "Hash salt",
        "Hash salt Value",
        "Direction",
        "<0:Ingress,1:Egress>",
        "Detail")
{
    ctc_ipfix_data_t use_data;
    uint8 index = 0;
    uint8 mask_len = 0;
    ipv6_addr_t ipv6_address;
    uint32 rst_hit = 0;
    uint32 rst_key_index = 0;
    int32 ret = CLI_SUCCESS;
    uint8 lchip = 0;
    uint32 detail = 0;
    uint32 entry_idx = 0;
    ctc_ipfix_traverse_t ipfix_traverse;
    ctc_field_key_t* p_field = NULL;
    ctc_xdata_field_t xdata_field[35];
    sal_memset(xdata_field, 0, sizeof(ctc_xdata_field_t)*35);
    sal_memset(&ipfix_traverse, 0, sizeof(ctc_ipfix_traverse_t));
    sal_memset(&use_data, 0, sizeof(ctc_ipfix_data_t));

    index = CTC_CLI_GET_ARGC_INDEX("flex-key");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("flex-key", use_data.key_type, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }
    else
    {

        index = CTC_CLI_GET_ARGC_INDEX("single");
        if (index != 0xFF)
        {
            use_data.key_type = CTC_IPFIX_KEY_HASH_IPV6_SINGLE;
        }
        else
        {
            use_data.key_type = CTC_IPFIX_KEY_HASH_IPV6;
        }
    }

    if (use_data.key_type >= CTC_IPFIX_KEY_HASH_FLEX_BASE)
    {
        use_data.flex_key.field_list = mem_malloc(MEM_CLI_MODULE, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        if (NULL == use_data.flex_key.field_list)
        {
            return CLI_ERROR;
        }
        sal_memset(use_data.flex_key.field_list, 0, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        p_field = use_data.flex_key.field_list;
        CTC_CLI_IPFIX_XKEY_FIELD_HASH_SET(p_field, CTC_CLI_IPFIX_KEY_ARG_CHECK(use_data.flex_key.field_num, MAX_XKEY_FIELD_NUM, p_field));
    }

    index = CTC_CLI_GET_ARGC_INDEX("xdata");
    if (0xFF != index)
    {
        use_data.xdata.num = ctc_cmd_get_map_array(1,(void*) (xdata_field),argv[index+2]);
        use_data.xdata.fields = xdata_field;
    }

    index = CTC_CLI_GET_ARGC_INDEX("src-gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("src-gport", use_data.gport, argv[index+1], 0, CTC_MAX_UINT32_VALUE);        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }
    index = CTC_CLI_GET_ARGC_INDEX("hash-field-sel");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("hash-field-sel", use_data.field_sel_id, argv[index+1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("profile-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("profile-id", use_data.profile_id, argv[index + 1],0,CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("gport", use_data.gport, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }


    index = CTC_CLI_GET_ARGC_INDEX("logic-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("lport", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_LOGIC_PORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("metadata");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("metadata", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_METADATA;
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-sa");
    if (index != 0xFF)
    {
        CTC_CLI_GET_IPV6_ADDRESS("ipv6", ipv6_address, argv[index+1]);
        CTC_CLI_GET_UINT8_RANGE("mask", mask_len, argv[index+3],0, CTC_MAX_UINT8_VALUE);
        use_data.l3_info.ipv6.ipsa_masklen = mask_len;
        use_data.l3_info.ipv6.ipsa[0] = sal_htonl(ipv6_address[0]);
        use_data.l3_info.ipv6.ipsa[1] = sal_htonl(ipv6_address[1]);
        use_data.l3_info.ipv6.ipsa[2] = sal_htonl(ipv6_address[2]);
        use_data.l3_info.ipv6.ipsa[3] = sal_htonl(ipv6_address[3]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-da");
    if (index != 0xFF)
    {
        CTC_CLI_GET_IPV6_ADDRESS("ipda", ipv6_address, argv[index+1]);
        CTC_CLI_GET_UINT8_RANGE("mask", mask_len, argv[index+3],0, CTC_MAX_UINT8_VALUE);
        use_data.l3_info.ipv6.ipda_masklen = mask_len;
        use_data.l3_info.ipv6.ipda[0] = sal_htonl(ipv6_address[0]);
        use_data.l3_info.ipv6.ipda[1] = sal_htonl(ipv6_address[1]);
        use_data.l3_info.ipv6.ipda[2] = sal_htonl(ipv6_address[2]);
        use_data.l3_info.ipv6.ipda[3] = sal_htonl(ipv6_address[3]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("src-cid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("src cid", use_data.src_cid, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_SRC_CID_VALID;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dst-cid");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("dst cid", use_data.dst_cid, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_DST_CID_VALID;
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("l4-type", use_data.l4_info.type.l4_type, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-sub-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("l4-sub-type", use_data.l4_info.l4_sub_type, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("aware-tunnel-info-en");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("aware-tunnel-info-en", use_data.l4_info.aware_tunnel_info_en, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-src-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("l4-src", use_data.l4_info.l4_port.source_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("l4-dst-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("l4-dst", use_data.l4_info.l4_port.dest_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("icmp-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("icmp-type", use_data.l4_info.icmp.icmp_type, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("icmp-code");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("icmp-code", use_data.l4_info.icmp.icmpcode, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("igmp-type");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("igmp-type", use_data.l4_info.igmp.igmp_type, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("tcp-flags");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("tcp-flags", use_data.l4_info.tcp_flags, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("gre-key");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("gre-key", use_data.l4_info.gre_key, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("dscp", use_data.l3_info.ipv6.dscp, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("flow-label");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("flow label", use_data.l3_info.ipv6.flow_label, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ttl");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("ttl", use_data.l3_info.ipv6.ttl, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ecn");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("ecn", use_data.l3_info.ipv6.ecn, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-protocol");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("ip-protocol", use_data.l4_info.type.ip_protocol, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("ip-frag");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("ip-frag", use_data.l3_info.ip_frag, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("tcp-flags");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("tcp-flags", use_data.l4_info.tcp_flags, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("vni");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("vni", use_data.l4_info.vni, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("wlan-radio-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("radio-id", use_data.l4_info.wlan.radio_id, argv[index+1], 0, CTC_MAX_UINT16_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("wlan-radio-mac");
    if (index != 0xFF)
    {
        CTC_CLI_GET_MAC_ADDRESS("radio-mac", use_data.l4_info.wlan.radio_mac, argv[index+1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("wlan-is-ctl-pkt");
    if (index != 0xFF)
    {
        use_data.l4_info.wlan.is_ctl_pkt = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("hash-salt");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("hash salt", use_data.hash_salt, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_RESOLVE_HASH_CONFLICT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dir");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("dir", use_data.dir, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("detail");
    if (index != 0xFF)
    {
        detail = 1;
    }

    lchip = g_api_lchip;
    ret = sys_usw_ipfix_get_entry_by_key(lchip, &use_data, &rst_hit, &rst_key_index);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

    ret = sys_usw_ipfix_get_ad_by_index(lchip, rst_key_index, &use_data);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

     ctc_cli_out("\n%-11s%-18s%-7s%-8s%-9s%-9s%-12s%-10s%-5s\n", "ENTRY_IDX", "ENTRY_TYPE", "PORT", "SEL_ID", "MAX_TTL", "MIN_TTL", "TIMESTAMP", "DIR", "PP");
    ctc_cli_out("----------------------------------------------------------------------------------------\n");
    if (detail == 1)
    {
        entry_idx = rst_key_index + (detail<<31);
    }
    else
    {
        entry_idx = rst_key_index;
    }
    ipfix_traverse.lchip_id = lchip;
    use_data.key_index = entry_idx;
    ret = sys_usw_ipfix_show_entry_info(&use_data, &ipfix_traverse);
    mem_free(use_data.flex_key.field_list);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }


    ctc_cli_out("\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_show_udf_hashkey,
        ctc_cli_usw_ipfix_show_udf_hashkey_cmd,
        "show ipfix entry-info by entry-key (flex-key KEY_TYPE origin |)udf-key (single|)(src-gport SRCPORT|hash-field-sel FIELD_ID){"CTC_CLI_IPFIX_KEY_PORT_STR "|profile-id PROFILE_ID |"CTC_CLI_IPFIX_KEY_UDF_STR"|" CTC_CLI_IPFIX_XKEY_STR "|xdata array-field FIELD|hash-salt VALUE} (dir DIR) (detail|)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Entry info",
        "By",
        "Entry key",
        "Flex key",
        "Key type value",
        "Origin",
        "UDF key",
        "Single UDF key",
        "Source phyPort",
        CTC_CLI_GPORT_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_DESC,
        CTC_CLI_FIELD_SEL_ID_VALUE,
        CTC_CLI_KEY_PORT_STR_DESC,
        "Config profile id",
        "Profile id",
        CTC_CLI_IPFIX_KEY_UDF_STR_DESC,
        CTC_CLI_IPFIX_XKEY_STR_DESC,
        "XDATA",
        "(LOCAL) XDATA as KEY-FIELD",
        "[[(LOCAL) XDATA WIDTH ,(LOCAL) XDATA OFFSET ,INVALID ,(LOCAL) XDATA MASK],[...]]",
        "Hash salt",
        "Hash salt Value",
        "Direction",
        "<0:Ingress,1:Egress>",
        "Detail")
{
    ctc_ipfix_data_t use_data;
    uint8 index = 0;
    uint32 rst_hit;
    uint32 rst_key_index;
    int32 ret = CLI_SUCCESS;
    uint8 lchip = 0;
    uint32 detail = 0;
    uint32 entry_idx = 0;
    ctc_ipfix_traverse_t ipfix_traverse;
    ctc_field_key_t* p_field = NULL;
    ctc_xdata_field_t xdata_field[35];
    sal_memset(xdata_field, 0, sizeof(ctc_xdata_field_t)*35);
    sal_memset(&ipfix_traverse, 0, sizeof(ctc_ipfix_traverse_t));
    sal_memset(&use_data, 0, sizeof(ctc_ipfix_data_t));

    index = CTC_CLI_GET_ARGC_INDEX("flex-key");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("flex-key", use_data.key_type, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }
    else
    {
        index = CTC_CLI_GET_ARGC_INDEX("single");
        if (index != 0xFF)
        {
            use_data.key_type = CTC_IPFIX_KEY_HASH_UDF_SINGLE;
        }
        else
        {
            use_data.key_type = CTC_IPFIX_KEY_HASH_UDF;
        }
    }

    if (use_data.key_type >= CTC_IPFIX_KEY_HASH_FLEX_BASE)
    {
        use_data.flex_key.field_list = mem_malloc(MEM_CLI_MODULE, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        if (NULL == use_data.flex_key.field_list)
        {
            return CLI_ERROR;
        }
        sal_memset(use_data.flex_key.field_list, 0, sizeof(ctc_field_key_t)*MAX_XKEY_FIELD_NUM);
        p_field = use_data.flex_key.field_list;
        CTC_CLI_IPFIX_XKEY_FIELD_HASH_SET(p_field, CTC_CLI_IPFIX_KEY_ARG_CHECK(use_data.flex_key.field_num, MAX_XKEY_FIELD_NUM, p_field));
    }

    index = CTC_CLI_GET_ARGC_INDEX("xdata");
    if (0xFF != index)
    {
        use_data.xdata.num = ctc_cmd_get_map_array(1,(void*) (xdata_field),argv[index+2]);
        use_data.xdata.fields = xdata_field;
    }

    index = CTC_CLI_GET_ARGC_INDEX("src-gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("src-gport", use_data.gport, argv[index+1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }
    index = CTC_CLI_GET_ARGC_INDEX("hash-field-sel");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("hash-field-sel", use_data.field_sel_id, argv[index+1], 0, CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("profile-id");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT8_RANGE("profile-id", use_data.profile_id, argv[index + 1],0,CTC_MAX_UINT8_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("gport");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("gport", use_data.gport, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_GPORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("logic-port");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("lport", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_LOGIC_PORT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("metadata");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16_RANGE("metadata", use_data.logic_port, argv[index + 1], 0, CTC_MAX_UINT16_VALUE);
        use_data.port_type = CTC_IPFIX_PORT_TYPE_METADATA;
    }

    index = CTC_CLI_GET_ARGC_INDEX("udf-id");
    if(index != 0xFF)
    {
        CTC_CLI_GET_UINT32("udf-id", use_data.udf_id, argv[index+1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("udf-data");
    if (INDEX_VALID(index))
    {
        uint32 data_num = 0;
        data_num = sal_sscanf(argv[index+1], "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", \
            (uint8*)use_data.udf,(uint8*)use_data.udf+1,(uint8*)use_data.udf+2,(uint8*)use_data.udf+3,(uint8*)use_data.udf+4,(uint8*)use_data.udf+5,(uint8*)use_data.udf+6,(uint8*)use_data.udf+7,(uint8*)use_data.udf+8,\
            (uint8*)use_data.udf+9,(uint8*)use_data.udf+10,(uint8*)use_data.udf+11,(uint8*)use_data.udf+12,(uint8*)use_data.udf+13,(uint8*)use_data.udf+14,(uint8*)use_data.udf+15);\
        if (data_num<16) {ctc_cli_out("  %%  Get udf data fail! \n");
            return CLI_ERROR;}
    }
    index = CTC_CLI_GET_ARGC_INDEX("hash-salt");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT16("hash salt", use_data.hash_salt, argv[index + 1]);
        use_data.flags |= CTC_IPFIX_DATA_RESOLVE_HASH_CONFLICT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("dir");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("dir", use_data.dir, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }

    index = CTC_CLI_GET_ARGC_INDEX("detail");
    if (index != 0xFF)
    {
        detail = 1;
    }

    lchip = g_api_lchip;
    ret = sys_usw_ipfix_get_entry_by_key(lchip, &use_data, &rst_hit, &rst_key_index);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

    ret = sys_usw_ipfix_get_ad_by_index(lchip, rst_key_index, &use_data);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(use_data.flex_key.field_list);
        return CLI_ERROR;
    }

    ctc_cli_out("\n%-11s%-18s%-7s%-8s%-9s%-9s%-12s%-10s%-5s\n", "ENTRY_IDX", "ENTRY_TYPE", "PORT", "SEL_ID", "MAX_TTL", "MIN_TTL", "TIMESTAMP", "DIR", "PP");
    ctc_cli_out("------------------------------------------------------------------------------------------\n");

    if (detail == 1)
    {
        entry_idx = rst_key_index + (detail<<31);
    }
    else
    {
        entry_idx = rst_key_index;
    }
    ipfix_traverse.lchip_id = lchip;
    use_data.key_index = entry_idx;
    ret = sys_usw_ipfix_show_entry_info(&use_data, &ipfix_traverse);
    mem_free(use_data.flex_key.field_list);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_show_by_index,
        ctc_cli_usw_ipfix_show_by_index_cmd,
        "show ipfix entry-info by (entry-idx IDX) {entry-type ((flex-key KEY_TYPE) |((mac-key|ipv4-key|ipv6-key|mpls-key|l2l3-key|udf-key)(single|)))} {dir DIR|detail|}",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Entry info",
        "By",
        "Entry index",
        "Entry index vlave",
        "Entry type",
        "Flex key",
        "Key type value",
        "L2 key",
        "Ipv4 key",
        "Ipv6 key",
        "Mpls key",
        "L2l3 key",
        "Udf key",
        "Single key",
        "Direction",
        "<0:Ingress,1:Egress>",
        "Detail")
{
    uint32 entry_idx = 0;
    int32 ret = CLI_SUCCESS;
    uint8 lchip = 0;
    ctc_ipfix_data_t  info;
    uint32 detail = 0;
    uint8 index = 0;
    uint8 key_type = 0;
    uint8 dir = CTC_INGRESS;
    ctc_ipfix_traverse_t ipfix_traverse;
    ctc_field_key_t field_list[MAX_XKEY_FIELD_NUM];
    ctc_xdata_field_t xdata_field_list[MAX_XDATA_FIELD_NUM];

    sal_memset(&ipfix_traverse, 0, sizeof(ctc_ipfix_traverse_t));
    sal_memset(&info, 0, sizeof(ctc_ipfix_data_t));
    sal_memset(field_list, 0, sizeof(ctc_field_key_t));
    sal_memset(xdata_field_list, 0, sizeof(ctc_xdata_field_t));

    index = CTC_CLI_GET_ARGC_INDEX("entry-type");
    if(index != 0xFF)
    {
        if (0xFF != CTC_CLI_GET_ARGC_INDEX("flex-key"))
        {
            info.flex_key.field_list = field_list;
            info.xdata.fields = xdata_field_list;
            CTC_CLI_GET_UINT32_RANGE("flex-key", key_type, argv[index+2], 0, CTC_MAX_UINT32_VALUE);
        }
        else if (0 == sal_memcmp("mac", argv[index + 1], sal_strlen("mac")))
        {
            key_type = CTC_IPFIX_KEY_HASH_MAC;
        }
        else if (0 == sal_memcmp("ipv4", argv[index + 1], sal_strlen("ipv4")))
        {
            key_type = CTC_IPFIX_KEY_HASH_IPV4;
            index = CTC_CLI_GET_ARGC_INDEX("single");
            if (index != 0xFF)
            {
               key_type=  CTC_IPFIX_KEY_HASH_IPV4_SINGLE;
            }
        }
        else if (0 == sal_memcmp("ipv6", argv[index + 1], sal_strlen("ipv6")))
        {
            key_type = CTC_IPFIX_KEY_HASH_IPV6;
            index = CTC_CLI_GET_ARGC_INDEX("single");
            if (index != 0xFF)
            {
                key_type =  CTC_IPFIX_KEY_HASH_IPV6_SINGLE;
            }
        }
        else if (0 == sal_memcmp("mpls", argv[index + 1], sal_strlen("mpls")))
        {
            key_type = CTC_IPFIX_KEY_HASH_MPLS;
            index = CTC_CLI_GET_ARGC_INDEX("single");
            if (index != 0xFF)
            {
                key_type =  CTC_IPFIX_KEY_HASH_MPLS_SINGLE;
            }
        }
        else if (0 == sal_memcmp("l2l3", argv[index + 1], sal_strlen("l2l3")))
        {
            key_type = CTC_IPFIX_KEY_HASH_L2_L3;
        }
        else if (0 == sal_memcmp("udf", argv[index + 1], sal_strlen("udf")))
        {
            key_type = CTC_IPFIX_KEY_HASH_UDF;
            index = CTC_CLI_GET_ARGC_INDEX("single");
            if (index != 0xFF)
            {
                key_type =  CTC_IPFIX_KEY_HASH_UDF_SINGLE;
            }
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("entry-idx");
    if (index != 0xFF)
    {
        CTC_CLI_GET_UINT32_RANGE("entry idx", entry_idx, argv[index + 1], 0, CTC_MAX_UINT32_VALUE);
    }
    index = CTC_CLI_GET_ARGC_INDEX("dir");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("dir", dir, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("detail");
    if (index != 0xFF)
    {
        detail = 1;
    }

    lchip = g_api_lchip;
    ret = sys_usw_ipfix_get_entry_by_index(lchip, entry_idx, dir, key_type, &info);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    info.dir = dir;
    ret = sys_usw_ipfix_get_ad_by_index(lchip, entry_idx, &info);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

     ctc_cli_out("\n%-11s%-18s%-7s%-8s%-9s%-9s%-12s%-10s%-5s\n", "ENTRY_IDX", "ENTRY_TYPE", "PORT", "SEL_ID", "MAX_TTL", "MIN_TTL", "TIMESTAMP", "DIR", "PP");
    ctc_cli_out("-------------------------------------------------------------------------------------------\n");
    if(detail == 1)
    {
        entry_idx = entry_idx + (detail<<31);
    }
    ipfix_traverse.lchip_id = lchip;
    info.key_index = entry_idx;
    ret = sys_usw_ipfix_show_entry_info(&info, &ipfix_traverse);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_ipfix_dump,
        ctc_cli_usw_ipfix_dump_cmd,
        "show ipfix entry-info {"CTC_CLI_PP_ID_STR"|}",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Entry info",
        CTC_CLI_PP_ID_DESC)
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint16 traverse_action = 0;
    ctc_ipfix_traverse_t ipfix_traverse;

    sal_memset(&ipfix_traverse, 0, sizeof(ctc_ipfix_traverse_t));
     /*traverse_action = SYS_IPFIX_DUMP_ENYRY_INFO;*/
    traverse_action = 0x0011;
    CTC_CLI_PP_ID_SET(index, ipfix_traverse.pp_id);
    ctc_cli_out("\n%-11s%-18s%-7s%-8s%-9s%-9s%-12s%-10s%-5s\n", "ENTRY_IDX", "ENTRY_TYPE", "PORT", "SEL_ID", "MAX_TTL", "MIN_TTL", "TIMESTAMP", "DIR", "PP");
    ctc_cli_out("------------------------------------------------------------------------------------------------\n");

    while (!ipfix_traverse.is_end)
    {
        ipfix_traverse.entry_num = 100;
        ipfix_traverse.start_index = ipfix_traverse.next_traverse_index;
        ipfix_traverse.user_data = & traverse_action;

        if (g_ctcs_api_en)
        {
            ret = ctcs_ipfix_traverse(g_api_ldev, sys_usw_ipfix_show_entry_info, &ipfix_traverse);
        }
        else
        {
            ret = ctc_ipfix_traverse(sys_usw_ipfix_show_entry_info, &ipfix_traverse);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
    }

    ctc_cli_out("\n");

    return CLI_SUCCESS;
}

int32
sys_usw_ipfix_remove_cmp(ctc_ipfix_data_t* p_info, void* user_data)
{
    return 0;
}
CTC_CLI(ctc_cli_usw_ipfix_remove_all_,
         ctc_cli_usw_ipfix_remove_all_cmd,
         "ipfix remove-all entry {"CTC_CLI_PP_ID_STR"|}",
         CTC_CLI_IPFIX_M_STR,
         "Remove all",
         "Entry",
         CTC_CLI_PP_ID_DESC)
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint16 traverse_action = 0;
    ctc_ipfix_traverse_t ipfix_traverse;

    sal_memset(&ipfix_traverse, 0, sizeof(ctc_ipfix_traverse_t));

    CTC_CLI_PP_ID_SET(index, ipfix_traverse.pp_id);
    while (!ipfix_traverse.is_end)
    {
        ipfix_traverse.entry_num = 100;
        ipfix_traverse.start_index = ipfix_traverse.next_traverse_index;
        ipfix_traverse.user_data = & traverse_action;

        if (g_ctcs_api_en)
        {
            ret = ctcs_ipfix_traverse_remove(g_api_ldev, sys_usw_ipfix_remove_cmp, &ipfix_traverse);
        }
        else
        {
            ret = ctc_ipfix_traverse_remove(sys_usw_ipfix_remove_cmp, &ipfix_traverse);
        }
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
    }
    return CLI_SUCCESS;
}

extern int32
sys_usw_ipfix_set_short_key_mode(uint8 lchip, uint8 enable);
CTC_CLI(ctc_cli_usw_ipfix_short_key_mode,
         ctc_cli_usw_ipfix_short_key_mode_cmd,
         "ipfix short-key (enable|disable) ",
         CTC_CLI_IPFIX_M_STR,
         "Short key mode",
         "Enable",
         "Disable")
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint8 enable = 0;
    

    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        enable = 1;
    }
    
    
    ret = sys_usw_ipfix_set_short_key_mode(g_api_lchip, enable);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    return CLI_SUCCESS;

}

#define ___IPFIX_FLEX_KEY___
CTC_CLI(ctc_cli_usw_ipfix_set_flex_key,
        ctc_cli_usw_ipfix_set_flex_key_cmd,
        "ipfix set flex-key-fields TYPE mode MODE {"CTC_CLI_FLEX_KEY_FIELD_STR_1"|} {"CTC_CLI_FLEX_KEY_FIELD_STR_2"|} (array-field FIELD |) \
        {origin-key-type ("CTC_CLI_USW_IPFIX_KEY_TYPE_STR")| dir (ingress|egress)}",
        CTC_CLI_IPFIX_M_STR,
        "Set",
        "Flex key fields ",
        "Flex key type",
        "Mode ",
        "0, none flex key mode; 1, append key; 2, double and append key 3,replace key",
        CTC_CLI_FLEX_KEY_FIELD_DESC_1,
        CTC_CLI_FLEX_KEY_FIELD_DESC_2,
        "Field array of local xdata key-field",
        "Two-dimensional Array,array number is ctc_xdata_field_t,format is [[WIDTH ,OFFSET ,DATA ,MASK ,FLAG],[...]].For example,[[4,0,0]],DATA and FLAG is invalid.",
        "Origin key type ",
        CTC_CLI_USW_IPFIX_KEY_TYPE_DESC,
        "Direction",
        "Ingress",
        "Egress")
{
    int32 ret;
    uint8 index = 0xFF;
    uint8  fk_end = CTC_IPFIX_KEY_HASH_FLEX_END;
    uint32 fld_id = 0;
    ctc_ipfix_flex_key_t flex_key;
    ctc_xdata_field_t xdata_field[35];
    sal_memset(&flex_key,0,sizeof(ctc_ipfix_flex_key_t));
    sal_memset(xdata_field,0,sizeof(ctc_xdata_field_t)*35);
    flex_key.xdata = mem_malloc (MEM_CLI_MODULE,sizeof(ctc_xdata_t));
    if (NULL == flex_key.xdata)
    {
        return CLI_ERROR;
    }
    sal_memset(flex_key.xdata,0,sizeof(ctc_xdata_t));

    CTC_CLI_USW_IPFIX_KEY_TYPE_SET
    CTC_CLI_GET_UINT8("flex-key-fields", flex_key.key_type, argv[0]);
    CTC_CLI_GET_UINT8("mode", flex_key.mode, argv[1]);
	
    index = CTC_CLI_GET_ARGC_INDEX("ingress");
    if (0xFF != index)
    {
        flex_key.dir = CTC_INGRESS;
        fk_end = index < fk_end ? index : fk_end;
    }
    index = CTC_CLI_GET_ARGC_INDEX("egress");
    if (0xFF != index)
    {
        flex_key.dir = CTC_EGRESS;
        fk_end = index < fk_end ? index : fk_end;
    }
    if (fk_end != CTC_IPFIX_KEY_HASH_FLEX_END)
    {
        for (index=1; index<fk_end; index++)
        {
            fld_id = sys_usw_acl_get_field_id(argv[index]);
            if (fld_id != 0xFFFFFFFF)
            {
                CTC_BMP_SET(flex_key.kset.w, fld_id);
            }
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("xdata");
    if (index != 0xFF)
    {
        flex_key.xdata->num = ctc_cmd_get_map_array(1,(void*) (xdata_field),argv[index+2]);
        flex_key.xdata->fields = xdata_field;
    }
    flex_key.xdata->type = flex_key.dir? CTC_XDATA_LOCAL_TYPE_EGS_IPFIX: CTC_XDATA_LOCAL_TYPE_IPFIX;

    if(flex_key.xdata->num)
    {
        CTC_BMP_SET(flex_key.kset.w, CTC_FIELD_KEY_XDATA);
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_ipfix_set_flex_key_fields(g_api_ldev, &flex_key);
    }
    else
    {
        ret = ctc_ipfix_set_flex_key_fields(&flex_key);
    }

    if(ret < 0)
    {
        ctc_cli_out("%% ret =%d, %s \n", ret, ctc_get_error_desc(ret));
        mem_free(flex_key.xdata);
        return CLI_ERROR;
    }
    mem_free(flex_key.xdata);

    return ret;
}

CTC_CLI(ctc_cli_usw_ipfix_get_flex_key,
        ctc_cli_usw_ipfix_get_flex_key_cmd,
        "show ipfix flex-key-fields TYPE mode MODE dir (ingress|egress)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Flex key fields",
        "Flex key fields value",
        "Mode ",
        "0, none flex key mode; 1, append key; 2, double and append key 3,replace key",
        "Direction",
        "Ingress",
        "Egress")
{
    int32 ret = CTC_E_NONE;
    uint8 lchip = 0;
    ctc_ipfix_flex_key_t flex_key;
    uint8 index = 0;
    sal_memset(&flex_key,0,sizeof(ctc_ipfix_flex_key_t));

    CTC_CLI_GET_UINT8("flex-key-fields", flex_key.key_type, argv[0]);
    CTC_CLI_GET_UINT8("mode", flex_key.mode, argv[1]);
    index = CTC_CLI_GET_ARGC_INDEX("ingress");
    if (0xFF != index)
    {
        flex_key.dir = CTC_INGRESS;
    }
    index = CTC_CLI_GET_ARGC_INDEX("egress");
    if (0xFF != index)
    {
        flex_key.dir = CTC_EGRESS;
    }

    if(g_ctcs_api_en)
    {
        ret = ctcs_ipfix_get_flex_key_fields(g_api_ldev, &flex_key);
    }
    else
    {
        ret = ctc_ipfix_get_flex_key_fields(&flex_key);
    }

    if(ret < 0)
    {
        ctc_cli_out("%% ret =%d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    lchip = g_api_lchip;
    
    sys_usw_ipfix_show_kset(lchip, &flex_key);
    return ret;
}


CTC_CLI(ctc_cli_usw_ipfix_get_flex_key_sets,
        ctc_cli_usw_ipfix_get_flex_key_sets_cmd,
        "show ipfix flex-key-sets origin-key-type ("CTC_CLI_USW_IPFIX_KEY_TYPE_STR") (mode VALUE) dir (ingress|egress)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_IPFIX_M_STR,
        "Flex key sets",
        "Origin key type",
        CTC_CLI_USW_IPFIX_KEY_TYPE_DESC,
        "Mode",
        "0, none flex key mode; 1, append key; 2, double and append key 3,replace key",
        "Direction",
        "Ingress",
        "Egress")

{
    int32 ret = CTC_E_NONE;
    uint8 lchip = 0;
    uint8 index = 0;
    ctc_ipfix_flex_key_t flex_key;
    sal_memset(&flex_key,0,sizeof(ctc_ipfix_flex_key_t));

    CTC_CLI_USW_IPFIX_KEY_TYPE_SET
    index = CTC_CLI_GET_ARGC_INDEX("ingress");
    if (0xFF != index)
    {
        flex_key.dir = CTC_INGRESS;
    }
    index = CTC_CLI_GET_ARGC_INDEX("egress");
    if (0xFF != index)
    {
        flex_key.dir = CTC_EGRESS;
    }
    index = CTC_CLI_GET_ARGC_INDEX("mode");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8_RANGE("mode", flex_key.mode, argv[index+1], 0, CTC_MAX_UINT8_VALUE);
    }
    if(g_ctcs_api_en)
    {
        ret = ctcs_ipfix_get_flex_key_sets(g_api_ldev, &flex_key);
    }
    else
    {
        ret = ctc_ipfix_get_flex_key_sets(&flex_key);
    }

    if(ret < 0)
    {
        ctc_cli_out("%% ret =%d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    lchip = g_api_lchip;
    
    sys_usw_ipfix_show_kset(lchip, &flex_key);
    return ret;
}

#define ___IPFIX_FLEX_KEY_END___


/**
 @brief  Initialize sdk oam module CLIs
*/
int32
ctc_usw_ipfix_cli_init(void)
{
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_status_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_stats_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_clear_stats_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_delete_by_index_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_dump_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_l2_hashkey_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_l2l3_hashkey_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_ipv4_hashkey_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_mpls_hashkey_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_ipv6_hashkey_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_udf_hashkey_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_by_index_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_remove_all_cmd);
    install_element(CTC_INTERNAL_MODE, &ctc_cli_usw_ipfix_short_key_mode_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_set_flex_key_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_get_flex_key_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_get_flex_key_sets_cmd);

    return CLI_SUCCESS;
}

int32
ctc_usw_ipfix_cli_deinit(void)
{
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_status_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_stats_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_clear_stats_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_delete_by_index_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_dump_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_l2_hashkey_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_l2l3_hashkey_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_ipv4_hashkey_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_mpls_hashkey_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_ipv6_hashkey_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_udf_hashkey_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_show_by_index_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_remove_all_cmd);
    uninstall_element(CTC_INTERNAL_MODE, &ctc_cli_usw_ipfix_short_key_mode_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_set_flex_key_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_get_flex_key_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_usw_ipfix_get_flex_key_sets_cmd);

    return CLI_SUCCESS;
}

#endif

